//
//  AppDelegate.m
//  StationManager
//
//  Created by Helong on 17/3/3.
//  Copyright © 2017年 Helong. All rights reserved.
//

#import "AppDelegate.h"
#import "MapViewController.h"
#import "HLNavigationController.h"
#import <BaiduMapAPI_Map/BMKMapView.h>
#import "BNCoreServices.h"
#import "LoginViewController.h"
#import "UserInfoModel.h"

@interface AppDelegate ()
{
    BMKMapManager *_mapManager;
}
@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // 启动图片延时: 1秒
    [NSThread sleepForTimeInterval:1];
    [self setKeyWindow];
    _mapManager = [[BMKMapManager alloc]init];
    // 如果要关注网络及授权验证事件，请设定generalDelegate参数
    BOOL ret = [_mapManager start:@"BZmb6rfAghBIHELkjxnDEhnKGBZQEiI7"  generalDelegate:nil];
    if (!ret) {
        NSLog(@"manager start failed!");
    }
 //初始化导航SDK
    [BNCoreServices_Instance initServices:@"BZmb6rfAghBIHELkjxnDEhnKGBZQEiI7"];
    [BNCoreServices_Instance startServicesAsyn:nil fail:nil];
    return YES;
}

- (void)setKeyWindow
{
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = WHITECOLOR;
    NSData *userData = [USER_DEFAULT objectForKey:@"userInfoModel"];
    UserInfoModel *userModel = [NSKeyedUnarchiver unarchiveObjectWithData:userData];
    if (userData && userModel) {
        self.window.rootViewController = [[HLNavigationController alloc] initWithRootViewController:[[MapViewController alloc] init]];
    }else{
        self.window.rootViewController = [[LoginViewController alloc]init];
    }
        [self.window makeKeyAndVisible];
}


- (void)applicationWillResignActive:(UIApplication *)application {

}


- (void)applicationDidEnterBackground:(UIApplication *)application {

}


- (void)applicationWillEnterForeground:(UIApplication *)application {

}


- (void)applicationDidBecomeActive:(UIApplication *)application {

}


- (void)applicationWillTerminate:(UIApplication *)application {
 
}


@end
